package com.algorithm.string_and_array;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

/**
 * 快慢指针
 */
@Slf4j
public class DoublePointerSolutionLC04 {
    public int removeElement(int[] nums, int val) {
        int i = 0;
        int j = 0;
        while (i< nums.length && j< nums.length){
            if (nums[i]==val && nums[j] == val ){
                j++;
            }else if (nums[j]!=val && nums[i]== val){
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
                i++;
                j++;
            }else if (nums[j]!=val && nums[i]!= val){
                i++;
                j++;
            }
        }
        return i;
    }

    @Test
    public void test(){
        int [] nums = {3,2,2,3};
        int val = 3;
        int i = removeElement(nums, val);
        log.info("return value is {}",i);
    }
}
